<?php
include 'lib/common.php';
$index = $_POST['index'];
//后台登录
if ('login' == $index) {
	if(NULL == $_POST['username']) {die(json(0,'账号不可为空！'));}
	if(NULL == $_POST['password']) {die(json(0,'密码不可为空！'));}
	echo adminlogin($_POST['username'],$_POST['password']);
}
//删除用户
if ('deluser' == $index) {
	//判断id是否存在
	if (isset($_POST['id'])) {
		$id = $_POST['id'];
		if (DB::query("DELETE FROM app_user WHERE Id='{$id}'")) {
			die(json(1,'删除成功！'));
		}else{
			die(json(0,'删除失败！'));
		}
	}else{
		die(json(0,'用户不存在！'));
	}
	DB::close();
}
//修改用户
if ('setuser' == $index) {
	if(NULL == $_POST['id']) {die(json(0,'没有此用户！'));}
	if(NULL == $_POST['username']) {die(json(0,'账号不可为空！'));}
	if(NULL == $_POST['password']) {$_POST['password'] = 123456;}
	if (!isset($_POST['vip'])) {$_POST['vip']=0;}
	if(NULL == $_POST['money']) {die(json(0,'金币不可为空！'));}
	echo setuser($_POST['id'],$_POST['username'],$_POST['password'],$_POST['money'],$_POST['vip']);
}
if ('adduser' == $index) {
	if(NULL == $_POST['username']) {die(json(0,'账号不可为空！'));}
	if(NULL == $_POST['password']) {$_POST['password'] = 123456;}
	if(!isset($_POST['vip'])) {$_POST['vip']=0;}
	if(NULL == $_POST['money']) {$_POST['money']=0;}
	echo adduser($_POST['username'],$_POST['password'],$_POST['money'],$_POST['vip']);
}